package me.xiaoyan.java.spring.controller;

import me.xiaoyan.java.spring.po.User;
import me.xiaoyan.java.spring.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class TestController {
    @Autowired
    private UserService userService;

    @RequestMapping(path="/test",method = {RequestMethod.POST,RequestMethod.GET})
    public String test(@RequestParam("id") Integer id, Model model){
        //将数据直接存放于model中即可
        model.addAttribute("now",System.currentTimeMillis());
        User user = userService.findById(id);
        model.addAttribute("user",user);
        return "user";
    }

    @RequestMapping("/test_view")
    public String index(){

        return "test";
    }
    
    @RequestMapping("/list")
    public String listView(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("list",userList );
        model.addAttribute("user_id",12);
        return "user_list";
    }
}
